package com.bistulpf.spring.service.impl;

import com.bistulpf.spring.annotation.Service;
import com.bistulpf.spring.service.TransferService;
import com.bistulpf.spring.annotation.Autowired;
import com.bistulpf.spring.annotation.Transactional;
import com.bistulpf.spring.dao.AccountDao;
import com.bistulpf.spring.pojo.Account;

@Service
@Transactional
public class TransferServiceImpl implements TransferService {


    @Autowired
    private AccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
           // int c = 1/0;
            accountDao.updateAccountByCardNo(from);


    }
}
